package logic

import (
	"context"
	"good/goodrpc/goodrpc"

	"good/api/internal/svc"
	"good/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodUpdateLogic {
	return &GoodUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodUpdateLogic) GoodUpdate(req *types.GoodUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	update, err := l.svcCtx.GoodRpc.GoodUpdate(l.ctx, &goodrpc.GoodUpdateRequest{
		Name:        req.Name,
		Cost:        float32(req.Cost),
		Market:      float32(req.Marke),
		Group:       float32(req.Group),
		Phone:       req.Phone,
		SendSmsCode: req.SendSmsCode,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "商品修改成功",
		Code:    200,
		Data:    update,
	}, nil
}
